import type { User, CodeType, UserInfo, PatientList, Patient } from '@/types/user'
import { request } from '@/utils/request'

/**
 * 用户登录
 * @param mobile 手机号
 * @param password 密码
 * @returns Promise
 */
export const loginByPassword = (mobile: string, password: string) => {
  return request.post<User>('/login/password', { mobile, password })
}

/**
 * 获取验证码
 * @param mobile 手机号
 * @param type 登录/注册
 * @returns Promise
 */
export const sendMobileCode = (mobile: string, type: CodeType) => {
  return request.get('/code', {
    params: {
      mobile,
      type
    }
  })
}

/**
 * 验证码登录
 * @param mobile 手机号
 * @param code 验证码
 * @returns Pormise
 */
export const loginByMobile = (mobile: string, code: string) => {
  return request.post<User>('/login', { mobile, code })
}

/**
 * 获取个人信息
 * @returns Promise
 */
export const getUserInfo = () => {
  return request.get<UserInfo>('/patient/myUser')
}

/**
 * 获取患者信息列表
 * @returns Promise
 */
export const getPatientList = () => {
  return request.get<PatientList>('/patient/mylist')
}

/**
 * 添加患者信息
 * @param patient 患者信息对象
 * @returns Promise
 */
export const addPatient = (patient: Patient) => {
  return request.post('/patient/add', patient)
}

/**
 * 编辑患者信息
 * @param patient 患者信息对象
 * @returns Promise
 */
export const editPatient = (patient: Patient) => {
  return request.put('/patient/update', patient)
}

/**
 * 删除患者信息
 * @param id 患者id
 * @returns Promise
 */
export const delPatient = (id: string) => { 
  return request.delete(`/patient/del/${id}`)
}

/**
 * 查询患者信息
 * @param id 患者id
 * @returns Promsie
 */
export const getPatientDetail = (id: string) => {
  return request.get<Patient>(`/patient/info/${id}`)
}